<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $uname = $_POST['username'];
    $email = $_POST['email'];
    $pass = $_POST['password'];
    $confirm_password = $_POST['confirm_password'];
    $address = $_POST['address'];

    // 插入数据库
    session_start();
    $servername = "localhost";
    $username = "root"; // 数据库用户名
    $password = "store"; // 数据库密码
    $dbname = "aiweb"; // 数据库名称

    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_error) {
        die("连接失败: " . $conn->connect_error);
    }

    $sql = "INSERT INTO user (uname, pass, email, address) VALUES ('$uname', '$pass', '$email', '$address')";
    if ($conn->query($sql) === TRUE) {
        echo "<script>alert('注册成功！'); window.location.href='pages/login-page.php';</script>";
    } else {
        echo "<script>alert('注册失败：" . $conn->error . "');</script>";
    }

    $conn->close();
}
?>
